home *** CD-ROM | disk | FTP | other *** search
/ QuickTime for the Web (2nd Edition) / QuickTime for the Web (2nd Edition).iso / pc / Demos / Mac / Matthew's Behaviors / Matthew'sMotionƒ / randomCrawl < prev    next >
Encoding:
INI File  |  2001-09-10  |  3.3 KB  |  55 lines

  1. [Name]
  2. RandomCrawl - From Matthew's Motion Suite.
  3. By Matthew Peterson, matthew@pinoko.berkeley.edu
  4.  
  5. [Description]
  6. 2-19-2000
  7. Drop this on a sprite, and crawl randomly around the sprite
  8. track.
  9.  
  10. [Parameters]
  11.  
  12.  
  13. [Idle]
  14. SpriteVars MP_crawlstep MP_crawlstepx MP_crawlcorner MP_crawlstepy
  15. //Random Crawl By Matthew Peterson
  16. //This behavior is a simple play on Brownian motion with a more
  17. //organic feel. The sprite will stretch a random corner out in
  18. //a random direction, and pull the rest of the sprite over. The
  19. //ability to strech sprites in this way is underused.
  20.  
  21. if(MP_crawlstep = 0) //first the corner stretches out
  22.     MP_crawlstepx = random(1,5)//The stretch distance
  23.     MP_crawlstepy = random(1,5)
  24.     //Check if the sprite goes out of bounds. If it does, stretch in
  25.     //The opposite direction
  26.     if(boundstop < 0)
  27.         MP_crawlcorner = 3
  28.     elseif(boundsright > trackwidth)
  29.         MP_crawlcorner = 4
  30.     elseif(boundsbottom > trackheight)
  31.         MP_crawlcorner = 1
  32.     elseif(boundsleft < 0)
  33.         MP_crawlcorner = 2
  34.     else
  35.         //If not out of bounds, stretch in a random direction
  36.         MP_crawlcorner = (tickcount + random(1,45)) rem 4 + 1 //random corner. Used tickcount to get more variance on PCs
  37.     endif
  38.     //Stretch the corner again
  39.     stretch(firstcornerx - MP_crawlstepx*2*(MP_crawlcorner=1),firstcornery- MP_crawlstepy*2*(MP_crawlcorner=1),secondcornerx + MP_crawlstepx*2*(MP_crawlcorner=2),secondcornery - MP_crawlstepy*2*(MP_crawlcorner=2), thirdcornerx + MP_crawlstepx*2*(MP_crawlcorner=3),thirdcornery+ MP_crawlstepy*2*(MP_crawlcorner=3),fourthcornerx- MP_crawlstepx*2*(MP_crawlcorner=4),fourthcornery+MP_crawlstepy*2*(MP_crawlcorner=4))
  40. elseif(MP_crawlstep = 1)
  41.     stretch(firstcornerx - MP_crawlstepx*2*(MP_crawlcorner=1),firstcornery- MP_crawlstepy*2*(MP_crawlcorner=1),secondcornerx + MP_crawlstepx*2*(MP_crawlcorner=2),secondcornery - MP_crawlstepy*2*(MP_crawlcorner=2), thirdcornerx + MP_crawlstepx*2*(MP_crawlcorner=3),thirdcornery+ MP_crawlstepy*2*(MP_crawlcorner=3),fourthcornerx- MP_crawlstepx*2*(MP_crawlcorner=4),fourthcornery+MP_crawlstepy*2*(MP_crawlcorner=4))
  42. elseif(MP_crawlstep < 6)//Then the sprite pulls itself to its stretched corner in 5 steps.
  43.     if(MP_crawlcorner = 1)//I could have done this all in one stretch command, but it would be harder to read, and take slightly more time to calculate.
  44.         stretch(firstcornerx,firstcornery,secondcornerx- MP_crawlstepx,secondcornery- MP_crawlstepy,thirdcornerx- MP_crawlstepx,thirdcornery- MP_crawlstepy,fourthcornerx- MP_crawlstepx,fourthcornery- MP_crawlstepy)
  45.     elseif(MP_crawlcorner = 2)
  46.         stretch(firstcornerx + MP_crawlstepx,firstcornery - MP_crawlstepy,secondcornerx,secondcornery,thirdcornerx+MP_crawlstepx,thirdcornery- MP_crawlstepy,fourthcornerx+ MP_crawlstepx,fourthcornery- MP_crawlstepy)
  47.     elseif(MP_crawlcorner = 3)
  48.         stretch(firstcornerx + MP_crawlstepx,firstcornery + MP_crawlstepy,secondcornerx+MP_crawlstepx,secondcornery+MP_crawlstepy,thirdcornerx,thirdcornery,fourthcornerx+MP_crawlstepx,fourthcornery+MP_crawlstepy)
  49.     elseif(MP_crawlcorner = 4)
  50.         stretch(firstcornerx -MP_crawlstepx,firstcornery + MP_crawlstepy,secondcornerx- MP_crawlstepx,secondcornery+ MP_crawlstepy,thirdcornerx- MP_crawlstepx,thirdcornery+ MP_crawlstepy,fourthcornerx,fourthcornery)
  51.     endif
  52. elseif(MP_crawlstep = 10)// Rest for a few idle events, and then start again.
  53.         MP_crawlstep = - 1
  54. endif
  55. MP_crawlstep = MP_crawlstep + 1